/* ---------- functions used to demonsatration ---------- */

$(document).ready(function(){
	
	/* ---------- Placeholder Fix for IE ---------- */
	$('input, textarea').placeholder();

	/* ---------- Auto Height texarea ---------- */
	$('textarea').autosize();   
	
	/*------- Main Calendar -------*/
	
	$('#external-events div.external-event').each(function() {

		// it doesn't need to have a start or end
		var eventObject = {
			title: $.trim($(this).text()) // use the element's text as the event title
		};
		
		// store the Event Object in the DOM element so we can get to it later
		$(this).data('eventObject', eventObject);
		
		// make the event draggable using jQuery UI
		$(this).draggable({
			zIndex: 999,
			revert: true,      // will cause the event to go back to its
			revertDuration: 0  //  original position after the drag
		});
		
	});
	
	var date = new Date();
	var d = date.getDate();
	var m = date.getMonth();
	var y = date.getFullYear();

	var calendar = $('#calendar').fullCalendar({
		header: {
			left: 'prev,next',
			center: 'title',
			right: 'agendaWeek,agendaDay'
		},
		titleFormat: {
			month: 'MMM yyyy',                         	// Sep 2009
			week: "MMM yyyy", 							// Sep 2009
			day: 'MMM d, yyyy'                  	// Sep 8, 2009
		},
		selectable: true,
		selectHelper: true,
		select: function(start, end, allDay) {
			var title = prompt('Event Title:');
			if (title) {
				calendar.fullCalendar('renderEvent',
					{
						title: title,
						start: start,
						end: end,
						allDay: allDay
					},
					true // make the event "stick"
				);
			}
			calendar.fullCalendar('unselect');
		},
		editable: true,
		events: [
			{
				id: 100,				
				start: new Date(y, m, 10),
				imageurl: '/static/demo/img/hamburger.png'
			},
			{
				id: 101,
				start: new Date(y, m, d-3),
				imageurl: '/static/demo/img/lettuce.png'
			},
			{
				id: 102,
				start: new Date(y, m, d+4),
				imageurl: '/static/demo/img/apple.png'
			}		
		],
		eventBackgroundColor: '#ff0000',
		eventBorderColor: '#ff0000',
		eventRender: function(event, eventElement) {
			if (event.imageurl)
			{
                eventElement.find("div.fc-event-inner").prepend("<img src='" + event.imageurl +"' width='20px' height='20px'>");
			}
		}
		
	});
		
	
});